
package net.ieslaferreria.infoCiutat;

import java.util.Vector;

/*
 * FECHA      HORA     NOMBRE                    COMENTARIO
 *------------------------------------------------------------------------
 * 09/05/08   19:16  JAVI                    creació implementació          
 * 22/05/08   17:30  JAVI                    codificació dels métodes
 * 28/05/08   19.13  JAVI                
 *
 * @author Alex, Javi, David y Sergio
 * 
 * 
 */

import org.garret.perst.Iterator;
import org.garret.perst.Key;
import org.garret.perst.Storage;


public class ArestaManagerImpl extends Root implements ArestaManager {

    public Vector getLlistaArestes() {
        Iterator i = nomCarrer.iterator();
        Vector v=new Vector();
        
            while( i.hasNext() ){
                Aresta a = (Aresta)i.next();
                v.addElement(a.getNom());
             }
        
      return v;
    }
    
    public Vector cerca(String cadena) {
        Iterator i = nomCarrer.prefixIterator(cadena);
      Vector v = new Vector(); 
     
     while(i.hasNext()){
         Aresta a = (Aresta)i.next();
         v.addElement(a);
     }
      return v;
    }

    public Aresta getAresta(int codi) {
        Aresta a = (Aresta)idAresta.get(new Key(codi));
        return a;
    }

    public Vector getLlistaArestes(String nomCarrer) {
         Iterator i = this.nomCarrer.prefixIterator(nomCarrer);
      Vector v = new Vector(); 
     
     while(i.hasNext()){
         Aresta a = (Aresta)i.next();
         v.addElement(String.valueOf(a.getCodi()));
     }
      return v;
    
    }

    public Aresta getLlistaArestes(String nomCarrer, int numero) {
        Iterator i = this.nomCarrer.prefixIterator(nomCarrer);
     
     Aresta af = new ArestaImpl();
     while(i.hasNext()){
         Aresta a = (Aresta)i.next();
      
         /*if(a.getNumeroInici() <= numero <= a.getNumeroFinal() || 
                 a.getNumeroInici() >= numero >= a.getNumeroFinal())*{
               af = a;
               
           }*/
     }
 
     return af;
      
    }

    public int getNumMinCarrer(String nomCarrer) {
      Iterator i = this.nomCarrer.prefixIterator(nomCarrer);
      Vector v = new Vector(); 
      int min = 0;
      
        while(i.hasNext()){
         Aresta a = (Aresta)i.next();
         v.addElement(a);
         }
      
      Aresta amin = (Aresta) v.firstElement();
      min = amin.getNumeroInici();
      return min;
    }

    public int getNumMaxCarrer(String nomCarrer) {
        Iterator i = this.nomCarrer.prefixIterator(nomCarrer);
      Vector v = new Vector(); 
      int max = 0;
      
        while(i.hasNext()){
         Aresta a = (Aresta)i.next();
         v.addElement(a);
         }
      
      Aresta amax = (Aresta) v.firstElement();
      max = amax.getNumeroFinal();
      return max;
    }
    public void afegirAresta(Vector v){
         int i=0;
       while(i < v.size()) {
           Vector va=(Vector) v.elementAt(i);
          Aresta a = new ArestaImpl();
          a.setCodi(Integer.parseInt(String.valueOf(va.elementAt(0))));
          a.setNom((String) va.elementAt(1));
          a.setPuntInici((Punt) va.elementAt(2));
          a.setPuntFinal((Punt) va.elementAt(3));
          a.setDistancia( Integer.parseInt(String.valueOf(va.elementAt(4))));
          a.setTemps(Integer.parseInt(String.valueOf(va.elementAt(5))));
          a.setNumeroInici(Integer.parseInt(String.valueOf(va.elementAt(6))));
          a.setNumeroFinal(Integer.parseInt(String.valueOf(va.elementAt(7))));       
          super.afegirDadesPerst(a);
          i++;
              }
         }
    public ArestaManagerImpl(){}
    
    public ArestaManagerImpl(Storage db){
        super(db);
        
    }
}
